﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Microsoft.Xna.Framework.Content.Pipeline;
using XnaAux;

namespace AnimationPipeline
{
    [ContentTypeWriter]
    public class AnimationClipsWriter : ContentTypeWriter<AnimationClips>
    {
        protected override void Write(ContentWriter aOutput, AnimationClips aClips)
        {
            aOutput.Write(aClips.Clips.Count);
            aOutput.WriteObject(aClips.SkelToBone);
            foreach (KeyValuePair<string, AnimationClips.Clip> lClipItem in aClips.Clips)
            {
                AnimationClips.Clip lClip = lClipItem.Value;

                aOutput.Write(lClip.Name);
                aOutput.Write(lClip.Duration);
                aOutput.Write(lClip.Keyframes.Length);
                foreach (List<AnimationClips.Keyframe> lKeyframes in lClip.Keyframes)
                {
                    aOutput.Write(lKeyframes.Count);

                    foreach (AnimationClips.Keyframe lKeyframe in lKeyframes)
                    {
                        
                        aOutput.Write(lKeyframe.Time);
                        aOutput.Write(lKeyframe.Rotation);
                        aOutput.Write(lKeyframe.Translation);
                    }
                }
            }
        }

        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return typeof(AnimationClipsReader).AssemblyQualifiedName;
        }
    }
}